<template>
  <div class="app-container">
    <div class="zd3">
      <div class="zd3-title">
        <p>
          <span>维修类型</span>
          <el-select v-model="repair" placeholder="请选择维修类型" class="userselect">
            <el-option
              v-for="item in repairList"
              :key="item.value"
              :label="item.name"
              :value="item.name"
            ></el-option>
          </el-select>
        </p>
        <h3 @click="getList">查询</h3>
        <h3 @click="addpeople" style="background: #0093FF">新增</h3>
        <h4 @click="resetList">重置</h4>
      </div>
      <div class="zd3-btm">
        <el-table
          :data="tableData"
          style="width: 100%;border-radius: 8px;"
          :show-header="showHeader"
          v-loading="loading"
        >
          <el-table-column type="index" align="center" label="序号" width="80" />
					<el-table-column align="center" label="维修原因" >
						<template slot-scope="scope">
							<div class="ellisp">{{scope.row.maintainName}}</div>
						</template>
					</el-table-column>
					<el-table-column align="center" label="维修内容">
						<template slot-scope="scope">
							<div class="ellisp">{{scope.row.maintainContent}}</div>
						</template>
					</el-table-column>
					<el-table-column align="center" width="100" prop="maintainPerson" label="维修人" />
					<el-table-column align="center" width="150" prop="maintainType" label="维修类型" />
					<el-table-column align="center" prop="remark" label="备注" />
					<el-table-column align="center" width="150" prop="updateTime" label="时间" />
          <el-table-column align="center" width="200" label="操作">
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="write(scope.row,scope.$index)">编辑</el-button>
              <el-popconfirm
                placement="top"
                hideIcon
                title="是否要删除此行？"
                @onConfirm="deleteRow(scope.row)"
              >
                <el-button type="text" size="small" slot="reference">删除</el-button>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          background
          hide-on-single-page
          layout="prev, pager, next"
          :total="total"
          @prev-click="goPrev"
          @next-click="goNext"
        />
      </div>
    </div>
    <el-dialog
      :visible.sync="dialogVisible"
      :modal-append-to-body="false"
      :modal="true"
      :close-on-click-modal="false"
      width="70%"
    >
      <div class="change">
				<p>
				  <span>维修原因</span>
				  <textarea v-model="tempData.maintainName" placeholder="请输入维修原因" />
				</p>
        <p>
          <span>维修内容</span>
					<textarea v-model="tempData.maintainContent" placeholder="请输入维修内容" />
        </p>
				<p>
				  <span>维修人</span>
					<input v-model="tempData.maintainPerson" placeholder="请输入维修人" />
				</p>
				<p>
				  <span>备注</span>
					<input v-model="tempData.remark" placeholder="请输入备注" />
				</p>
				<p>
				  <span>维修类型</span>
				  <el-select v-model="tempData.maintainType" placeholder="请选择维修类型" class="userselect">
				    <el-option
				      v-for="item in repairList"
				      :key="item.value"
				      :label="item.name"
				      :value="item.name"
				    ></el-option>
				  </el-select>
				</p>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="save">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getRepair, addRepair, updateRepair, deleteRepair} from "@/api/bumen";
let repairid;
export default {
  data() {
    return {
      content: "",
      total: 1,
      showHeader: true,
      loading: true,
      tableData: [],
      dialogVisible: false,
      tempData: "",
      tempIndex: -1,
			repairList: [{
				name: '维修',
				value: 0
			},
			{
				name: '检修',
				value: 1
			}],
			repair: ''
    };
  },
  mounted() {
		if(this.$route.params.options){
			let temp1 = JSON.parse(this.$route.params.options)
			repairid = temp1.id
			console.log(temp1,repairid)
			this.getList();
		}
  },
  methods: {
    getList() {
      const param = {
        maintainType : this.repair ? this.repair : null,
				departFacilityId: repairid
      };
      getRepair(param).then(res => {
        console.log(res);
        this.tableData = res.data.list;
        this.loading = false;
      });
    },
    write(item, index) {
      console.log(item);
      this.tempIndex = index;
			// this.$router.push({
			// 	name: 'Writereadilytake',
			// 	params: {
			// 		options: JSON.stringify(item)
			// 	}
			// })
      this.tempData = { ...item }
      this.dialogVisible = true
    },
    save() {
      if (this.tempIndex == -1) {
				this.tempData.departFacilityId = repairid
        addRepair(this.tempData).then(res => {
          console.log(res)
          this.$message({
            showClose: true,
            message: res.message,
            type: "success"
          })
          this.getList()
          this.dialogVisible = false
        });
      } else {
        updateRepair(this.tempData).then(res => {
          console.log(res)
          this.$message({
            showClose: true,
            message: res.message,
            type: "success"
          })
          this.getList()
          this.dialogVisible = false
        });
      }
    },
    deleteRow(item) {
      console.log("删除")
      deleteRepair(item.id).then(res => {
        console.log(res)
        this.$message({
          showClose: true,
          message: res.message,
          type: "success"
        })
        this.getList()
      })
    },
    goPrev(page) {
      console.log(page);
    },
    goNext(page) {
      console.log(page);
    },
    resetList() {
      this.repair = "";
    },
    addpeople() {
      // this.$router.push({
      // 	name: 'Writereadilytake'
      // })
			this.dialogVisible = true
			this.tempIndex = -1
			this.tempData = {
				maintainName: '',
				maintainContent: '',
				maintainPerson: '',
				remark: '',
				maintainType: ''
			}
    }
  }
};
</script>

<style lang="scss" scoped>
/deep/.el-button--primary {
  color: #fff;
  background-color: #18a05e !important;
  border-color: #18a05e !important;
}
/deep/.el-button--primary:hover,
.el-button--primary:focus {
  background: #18a05e !important;
  border-color: #18a05e !important;
  color: #fff !important;
}
/deep/.el-button:hover,
.el-button:focus {
  color: #18a05e;
  background-color: transparent;
}
/deep/.el-button--primary {
  color: #fff;
  background-color: #18a05e;
  border-color: #18a05e;
}
/deep/.el-button--text {
  color: #00c666 !important;
}
.ellisp{
	width: 100%;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3;
	overflow: hidden;
	text-align: left;
}
.app-container {
  padding: 10px;
}
.rolestip {
  width: 100%;
  display: flex;
  justify-content: center;
}
.inps {
  width: 100%;
  height: 32px;
  line-height: 32px;
  padding-left: 10px;
  background: none;
  border: none;
  color: #333;
}
.inps-active {
  width: 100%;
  height: 32px;
  line-height: 32px;
  padding-left: 10px;
  // background:#ccc;
  border: none;
  color: #333;
}
.s-img{
  width: 80px;
  height: 80px;
}
.zd3-title {
  height: 80px;
  display: flex;
  align-items: center;
  padding: 0 20px;
  position: relative;
  background: #ffffff;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.1);

  > p {
    font-size: 14px;
    color: #333;
    margin-right: 50px;

    > span {
      padding-right: 20px;
    }

    > input {
      width: 200px;
      height: 32px;
      // background: #ccc;
      border-radius: 3px;
      border: 1px solid #ccc;
      padding-left: 10px;
      color: #333;
    }
  }

  > h3 {
    width: 64px;
    height: 32px;
    background: #18a05e;
    border-radius: 3px;
    margin: 0 30px 0 0;
    color: #fff;
    font-size: 14px;
    line-height: 32px;
    font-weight: 100;
    text-align: center;
    cursor: pointer;
  }

  > h4 {
    width: 64px;
    height: 32px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    color: #333;
    font-size: 14px;
    line-height: 32px;
    font-weight: 100;
    text-align: center;
    cursor: pointer;
  }
}
.zd3-btm /deep/.btn-prev:after {
  content: "上一页";
}
.zd3-btm /deep/.btn-next:before {
  content: "下一页";
}
.zd3-btm /deep/.btn-prev,
.zd3-btm /deep/.btn-next {
  width: 65px;
}
.zd3-btm {
  background: rgba(255, 255, 255, 1);
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  margin-top: 10px;
  overflow: hidden;
  &-title {
    display: flex;
    align-items: center;
    height: 70px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    background: #ffffff;
    > p {
      text-align: center;
      font-size: 16px;
      color: #333;
    }
  }
  .el-pagination {
		white-space: nowrap;
		padding: 15px 5px;
		color: #303133;
		font-weight: bold;
	}
  .addDate {
    margin: 20px 32px 10px 32px;
    height: 32px;
    border-radius: 3px;
    text-align: center;
    line-height: 32px;
    font-size: 14px;
    color: #333;
    cursor: pointer;
    border: 1px dashed rgba(0, 0, 0, 0.25);
  }
  .el-button--text {
    margin: 0 15px;
  }
}
.change {
  display: flex;
  flex-wrap: wrap;
  > p {
    width: 50%;
    font-size: 14px;
    display: flex;
    align-items: center;
    color: #333;
    /deep/.el-input__inner {
      width: inherit;
      background: none;
      height: 32px;
      // line-height: 32px;
      color: #333;
      border: 1px solid rgba(0, 0, 0, 0.1);
      padding: 0 25px;
    }
    /deep/.el-input__icon {
      line-height: 32px;
    }
    .userselect {
      // max-width: 250px;
      flex: 1;
    }

    > span {
      display: block;
      width: 120px;
      text-align: right;
      padding-right: 15px;
    }
    > input {
      width: inherit;
      flex: 1;
      height: 32px;
      border-radius: 3px;
      border: 1px solid rgba(0, 0, 0, 0.1);
      padding-left: 10px;
      color: #333;
    }
		> textarea{
			width: inherit;
			flex: 1;
			height: 60px;
			border-radius: 3px;
			border: 1px solid rgba(0, 0, 0, 0.1);
			padding: 10px;
		}
  }
}
</style>
